#!/bin/bash
# 检查 build-essential 包是否未安装，如果是，则安装它
if ! dpkg -s build-essential > /dev/null 2>&1; then
    apt-get update -y
    apt-get install -y build-essential
fi
#检查 cmake 是否已安装
if ! command -v cmake >/dev/null 2>&1; then
    echo "cmake 未安装正在尝试安装"
    apt-get update -y
    apt-get install -y cmake
fi
# 获取当前脚本的绝对路径
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
cd $(dirname $SCRIPT_PATH)
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "构建失败"
    exit 1
fi
#rm -rf /opt/external/project/ssh/libssh-0.11.2/src/ssh_build-stamp/ssh_build-configure*
#rm -rf /opt/external/project/mysql/client/mysql-9.4.0/src/mysql_client_build_mysql-9.4.0-stamp/mysql_client_build_mysql-9.4.0-download*
cd ..
CMAKEWORKDIR=$(pwd)
# 生成临时文件
#build_DIR="/tmp/$(date +"%Y-%m-%d-%H-%M-%S")"
BUILD_DIR="/tmp/build/library-manager/debug/android_manage"
#删除 临时文件
rm -rf $BUILD_DIR
# 生成构建目录
cmake -G "Unix Makefiles" \
-D CMAKE_BUILD_TYPE=debug \
-D CMAKE_INSTALL_PREFIX=/opt/android \
-D ANDROID_NDK_ROOT=/mnt/android_home/ndk/android-ndk-r28c \
-D CMAKE_TOOLCHAIN_FILE=/mnt/android_home/ndk/android-ndk-r28c/build/cmake/android.toolchain.cmake \
-D ANDROID_ABI=arm64-v8a \
-D ANDROID_PLATFORM=21 \
-D ANDROID_STL=c++_static \
-D CMAKE_PREFIX_PATH=/opt/android/module/prefix/android/arm64-v8a/21 \
-D MODULE_PREFIX=/opt/android/module \
-D WITH_ZLIB=OFF \
-D WITH_OPENSSL=OFF \
-D WITH_FFMPEG=OFF \
-D FFMPEG_TAG=n8.0 \
-S $CMAKEWORKDIR -B $BUILD_DIR
#cmake --build $BUILD_DIR --target ffmpeg_n8.0-configure
cmake --build $BUILD_DIR -j$(nproc)
# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "构建失败"
    rm -rf $BUILD_DIR
    exit 1
fi









